home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 2410 / 2410.xpi / chrome / content / foxmarks-dialog.js < prev    next >
Text File  |  2010-01-28  |  39KB  |  956 lines

  1. /*
  2.  Copyright 2005-2009 Foxmarks Inc.
  3.  
  4.  foxmarks-dialog.js: Implements the main foxmarks options dialog.
  5.  
  6.  */
  7.  
  8. // TO DO:
  9. // * Use synchronize method for preferences
  10.  
  11. var dialogMgr = {
  12.     panes: {
  13.         // Status Tab
  14.         status: {
  15.             onSetup: function(mgr){
  16.                 var os = Cc["@mozilla.org/observer-service;1"].
  17.                     getService(Ci.nsIObserverService);
  18.                 os.addObserver(this, "foxmarks-service", false);
  19.                 os.addObserver(this, "foxmarks-statechange", false);
  20.                 this.doc = document;
  21.                 this.window = window;
  22.                 this.updateStatus();
  23.  
  24.                 if (!Xmarks.gSettings.haveSynced && !Xmarks.gSettings.username) {
  25.                     var uo = document.getElementById("useown").checked;
  26.                     document.getElementById("foxmarks-statusdeck").selectedIndex = uo ? 0 :1;
  27.                 }
  28.             },
  29.             onUnload: function(){
  30.                 var os = Cc["@mozilla.org/observer-service;1"].
  31.                     getService(Ci.nsIObserverService);
  32.                 try {
  33.                     os.removeObserver(this, "foxmarks-service");
  34.                     os.removeObserver(this, "foxmarks-statechange");
  35.                 } catch (e) {
  36.                     Xmarks.LogWrite("Warning: removeObserver failed.");
  37.                 }
  38.             },
  39.             onOK: function(){},
  40.             onCancel: function(){},
  41.             setErrorMessaging: function(addThem,err){
  42.                 if(addThem){
  43.                     var box = this.doc.getElementById('errorbox');
  44.                     if(box){
  45.                         box.parentNode.removeChild(box);
  46.                     }
  47.                     box = this.doc.createElement('groupbox');
  48.                     box.setAttribute('width', '50');
  49.                     box.setAttribute('style', 'padding-left: 42px;');
  50.                     
  51.                     var label = this.doc.createElement('label');
  52.                     label.setAttribute('value',
  53.                         Xmarks.MapError(err) +"\n"
  54.                     );
  55.                     label.setAttribute('style',
  56.                         'font-weight: bold; margin-left: -2px;'
  57.  
  58.                     );
  59.                     box.appendChild(label);
  60.                     var errMessage = Xmarks.MapErrorMessage(err);
  61.                     var errUrl = Xmarks.MapErrorUrl(err);
  62.                     if(errMessage.length > 0){
  63.                         var desc = this.doc.createElement('description');
  64.                         var textNode = this.doc.createTextNode(
  65.                             Xmarks.MapErrorMessage(err)
  66.                         );
  67.                         desc.appendChild(textNode);
  68.                         box.appendChild(desc);
  69.                     }
  70.  
  71.                     
  72.                     if(errUrl.length > 0){
  73.                         var box2 = this.doc.createElement('vbox');
  74.                         box2.setAttribute('flex', '1');
  75.                         box2.setAttribute('align', 'end');
  76.  
  77.                         var button = this.doc.createElement('button');
  78.                         button.setAttribute('label',
  79.                         Xmarks.Bundle().GetStringFromName("dialog.status.button")
  80.                         );
  81.                         button.setAttribute('oncommand', 
  82.                             'dialogMgr.panes.status.moreInfo("' + errUrl + '");'
  83.                         );
  84.                         box2.appendChild(button);
  85.                         box.appendChild(box2);
  86.                     }
  87.                     box.setAttribute('id', 'errorbox');
  88.                     this.doc.getElementById('statusbox').appendChild(box);
  89.                    // this.window.sizeToContent();
  90.                 } else {
  91.                     var box = this.doc.getElementById('errorbox');
  92.                     if(box){
  93.                         box.parentNode.removeChild(box);
  94.                     }
  95.                     // this.window.sizeToContent();
  96.                 }
  97.             },
  98.  
  99.             observe: function(subject, topic, data) {
  100.                 if(topic == "foxmarks-service"){
  101.                     var result = eval(data);
  102.                     switch(result.status){
  103.                         case 1:
  104.                         case 3:
  105.                             this.updateStatus('working');
  106.                             break;
  107.                         case 0:
  108.                             this.updateStatus('ready');
  109.                             break;
  110.                         case 2:
  111.                             this.updateStatus('dirty');
  112.                             break;
  113.                         default:
  114.                             this.updateStatus('error', result.status);
  115.                             break;
  116.                     }
  117.                } else if(topic == "foxmarks-statechange"){
  118.                     switch(data){
  119.                         case 'ready':
  120.                         case 'dirty':
  121.                         case 'working':
  122.                         case 'error':
  123.                             this.updateStatus(data);
  124.                             break;
  125.                     }
  126.                }
  127.             },
  128.             moreInfo: function(err){
  129.                 Xmarks.OpenInNewWindow(err);
  130.             },
  131.             updateStatus: function(state, errorStatus){
  132.                 if(state === undefined){
  133.                     var foxmarks = Cc["@foxcloud.com/extensions/foxmarks;1"]
  134.                         .getService(Ci.nsIFoxmarksService);
  135.                     state = foxmarks.getState();
  136.                 }
  137.                 var image = this.doc.getElementById('status-image');
  138.                 var text = this.doc.getElementById('status-text');
  139.                 if(errorStatus === undefined){
  140.                     errorStatus = Xmarks.gSettings.lastError;
  141.                 }
  142.                 switch(state){
  143.                     case 'ready':
  144.                         this.setErrorMessaging(false);
  145.                         image.setAttribute('src',
  146.                             "chrome://foxmarks/skin/images/status-good.png");
  147.                         text.setAttribute('value',
  148.                             Xmarks.Bundle().GetStringFromName("dialog.status.good")
  149.                             );
  150.                         break;
  151.                     case 'dirty':
  152.                         this.setErrorMessaging(false);
  153.                         image.setAttribute('src',
  154.                             "chrome://foxmarks/skin/images/status-dirty.png");
  155.                         text.setAttribute('value',
  156.                             Xmarks.Bundle().GetStringFromName("dialog.status.dirty")
  157.                             );
  158.                         break;
  159.                     case 'working':
  160.                         this.setErrorMessaging(false);
  161.                         image.setAttribute('src',
  162.                             "chrome://foxmarks/skin/images/wheel36x28.gif");
  163.                         text.setAttribute('value',
  164.                             Xmarks.Bundle().GetStringFromName("dialog.status.working")
  165.                             );
  166.                         break;
  167.                     case 'error':
  168.                         image.setAttribute('src',
  169.                             "chrome://foxmarks/skin/images/status-bad.png");
  170.                         text.setAttribute('value',
  171.                             Xmarks.Bundle().GetStringFromName("dialog.status.bad")
  172.                             );
  173.                         this.setErrorMessaging(true, errorStatus);
  174.                         break;
  175.                 }
  176.             }
  177.         },
  178.         // General Tab
  179.         general: { 
  180.            onSetup: function(mgr){
  181.                 this.data = {
  182.                     username: Xmarks.gSettings.username,
  183.                     password: Xmarks.gSettings.passwordNoPrompt,
  184.                     rememberPassword: Xmarks.gSettings.rememberPassword,
  185.                     synchOnTimer: Xmarks.gSettings.synchOnTimer,
  186.                     syncOnShutdown: Xmarks.gSettings.syncOnShutdown,
  187.                     syncOnShutdownAsk: Xmarks.gSettings.syncOnShutdownAsk,
  188.                 };
  189.                 // Settings that are too complex to handle via prefwindow
  190.                 document.getElementById("password").value =
  191.                     Xmarks.gSettings.passwordNoPrompt;
  192.                 document.getElementById("synconshutdown").checked =
  193.                     Xmarks.gSettings.syncOnShutdown;
  194.                 document.getElementById("askfirst").checked =
  195.                     Xmarks.gSettings.syncOnShutdownAsk;
  196.                 this.syncOnShutdownChanged();
  197.            },
  198.            resetNameAndPassword: function(){
  199.                 document.getElementById("username").value =
  200.                     Xmarks.gSettings.username;
  201.                 document.getElementById("password").value =
  202.                     Xmarks.gSettings.passwordNoPrompt;
  203.  
  204.            },
  205.            onOK: function(){
  206.                 Xmarks.gSettings.username = 
  207.                     document.getElementById("username").value;
  208.            },
  209.  
  210.            onCancel: function(){
  211.                 var name;
  212.                 for(name in this.data){
  213.                     if(this.data.hasOwnProperty(name)){
  214.                         Xmarks.gSettings[name] = this.data[name];
  215.                     }
  216.                 }
  217.            },
  218.            forgotPassword: function(){
  219.                 Xmarks.OpenInNewWindow("http://" + Xmarks.gSettings.acctMgrHost + 
  220.                         "/login/forgot_password");
  221.            },
  222.            syncOnShutdownChanged: function() {
  223.                 document.getElementById("askfirst").disabled =
  224.                     !document.getElementById("synconshutdown").checked;
  225.            },
  226.            syncOnShutdownToPreference: function() {
  227.                 if (document.getElementById("synconshutdown").checked) {
  228.                     return 1;
  229.                 }
  230.                 return 0;
  231.            }
  232.         },
  233.         sync: { // sync tab
  234.            onSetup: function(mgr){
  235.             this.mgr = mgr;
  236.  
  237.             this.resetSyncTypes();
  238.            },
  239.            
  240.            resetSyncTypes: function(){
  241.             this.data = {
  242.                bookmarks: Xmarks.gSettings.isSyncEnabled("bookmarks"),
  243.                passwords: Xmarks.gSettings.isSyncEnabled("passwords")
  244.             };
  245.             // Settings for passwords
  246.             var passwordSyncEnabled = Xmarks.gSettings.isSyncEnabled("passwords");
  247.  
  248.             document.getElementById("sync-passwords").checked =
  249.                 passwordSyncEnabled;
  250.             document.getElementById("sync-resetpin").disabled =
  251.                 !passwordSyncEnabled; 
  252.             document.getElementById("sync-deletepasswords").disabled =
  253.                 !passwordSyncEnabled;
  254.             if(Xmarks.gSettings.useOwnServer){
  255.                 document.getElementById("sync-deletepasswords").disabled = true;
  256.             }
  257.                 
  258.             document.getElementById("sync-bookmarks").checked =
  259.                 Xmarks.gSettings.isSyncEnabled("bookmarks");
  260.  
  261.             if ("@mozilla.org/login-manager;1" in Cc) {
  262.                 document.getElementById("onlyFF3").hidden = true;
  263.             }
  264.             else {
  265.                 document.getElementById("sync-resetpin").disabled = true;
  266.                 document.getElementById("sync-deletepasswords").disabled = true;
  267.                 document.getElementById("sync-passwords").disabled = true;
  268.             }
  269.  
  270.            },
  271.            onOK: function(){
  272.  
  273.            },
  274.            onCancel: function(){
  275.                 Xmarks.gSettings.setSyncEnabled("passwords",this.data.passwords); 
  276.                 Xmarks.gSettings.setSyncEnabled("bookmarks",this.data.bookmarks); 
  277.            },
  278.            handlePasswordSync: function(){
  279.                 var d = document;
  280.                 var passwordSyncEnabled =
  281.                     d.getElementById("sync-passwords").checked; 
  282.                 var result = {
  283.                     doSync: false
  284.                 };
  285.                 if(passwordSyncEnabled){
  286.                         window.openDialog(
  287.                             "chrome://foxmarks/content/foxmarks-setup.xul",
  288.                             "Xmarks", "chrome,dialog,modal,centerscreen",
  289.                             true,
  290.                             "askforPIN",
  291.                             result
  292.                         );
  293.                         passwordSyncEnabled = Xmarks.gSettings.pinNoPrompt != null;
  294.                         if(!passwordSyncEnabled){
  295.                             d.getElementById("sync-passwords").checked = false; 
  296.                         }
  297.                         if(result.doSync){
  298.                             Xmarks.gSettings.setSyncEnabled("passwords",
  299.                                 passwordSyncEnabled);
  300.                             if(Xmarks.gSettings.securityLevel == -1){
  301.                                 Xmarks.Alert(Xmarks.Bundle().GetStringFromName
  302.                                     ("msg.resetpin.securitylevelchange"));
  303.                             }
  304.                             Xmarks.gSettings.securityLevel = 1;
  305.                             d.getElementById("encrypt").setAttribute(
  306.                                 "value", "1");
  307.                             if(this.mgr.synchronizeNow()){
  308.                                 var prefwindow = 
  309.                                     document.getElementById("foxmarks-settings");
  310.                                 prefwindow.showPane(
  311.                                     document.getElementById("foxmarks-mainpane")
  312.                                 );
  313.                             }
  314.                         }
  315.                 }
  316.                 else {
  317.                     Xmarks.gSettings.removePIN();
  318.                 }
  319.  
  320.                 Xmarks.gSettings.setSyncEnabled("passwords",passwordSyncEnabled); 
  321.                 d.getElementById("sync-deletepasswords").disabled =
  322.                     !passwordSyncEnabled; 
  323.                 d.getElementById("sync-resetpin").disabled =
  324.                     !passwordSyncEnabled; 
  325.            },
  326.            handleBookmarkSync: function(){
  327.                 var d = document;
  328.                 var enabled =d.getElementById("sync-bookmarks").checked; 
  329.  
  330.                 Xmarks.gSettings.setSyncEnabled("bookmarks",enabled); 
  331.            },
  332.            doDeletePasswords: function(){
  333.                 var ps = Components.classes
  334.                     ["@mozilla.org/embedcomp/prompt-service;1"]
  335.                     .getService(Components.interfaces.nsIPromptService);
  336.                if(ps.confirm(null,"Xmarks", Xmarks.Bundle().
  337.                     GetStringFromName("msg.deletepasswords.confirm"))
  338.                ){
  339.                     this.mgr.onOK();
  340.                     if(!Xmarks.PerformAction("deletepasswords", null)){
  341.                         Xmarks.gSettings.setSyncEnabled("passwords", false);
  342.                         document.getElementById("sync-passwords").checked = 
  343.                             false; 
  344.                         document.getElementById("sync-resetpin").disabled =
  345.                             true;
  346.                         document.getElementById("sync-deletepasswords").
  347.                             disabled = true;
  348.                         Xmarks.gSettings.removePIN();
  349.                         ps.alert(null, "Xmarks", Xmarks.Bundle().
  350.                                 GetStringFromName("msg.deletepasswords.success")
  351.                         );
  352.                     }
  353.                     else {
  354.                         var prefwindow = 
  355.                             document.getElementById("foxmarks-settings");
  356.                         prefwindow.showPane(
  357.                                 document.getElementById("foxmarks-mainpane")
  358.                         );
  359.                     }
  360.                }
  361.  
  362.            },
  363.            doResetPIN: function(){
  364.                 var result = {
  365.                     doSync: false
  366.                 };
  367.                 window.openDialog(
  368.                     "chrome://foxmarks/content/foxmarks-resetpin.xul",
  369.                     "_blank",
  370.                     "chrome,dialog,modal,centerscreen", result);
  371.                 if(result.doSync){
  372.                     Xmarks.gSettings.setSyncEnabled("passwords",true); 
  373.                    Xmarks.gSettings.setMustUpload("passwords", true);
  374.                    if(!this.mgr.synchronizeNow()){
  375.                         Xmarks.Alert(Xmarks.Bundle().
  376.                             GetStringFromName("msg.resetpin.success"));
  377.                    }
  378.                     else {
  379.                         var prefwindow = 
  380.                             document.getElementById("foxmarks-settings");
  381.                         prefwindow.showPane(
  382.                                 document.getElementById("foxmarks-mainpane")
  383.                         );
  384.                     }
  385.                 }
  386.             },
  387.             moreSyncSoon: function(){
  388.                 Xmarks.OpenInNewWindow("http://wiki.xmarks.com/wiki/Foxmarks:_More_Syncing_Coming_Soon"); 
  389.             }
  390.         },
  391.         restore: { // restore tab
  392.             _data: null,
  393.             onSetup: function(mgr){
  394.                 this.mgr = mgr;
  395.                 this.box = document.getElementById("foxmarks-restorelist");
  396.                 var self = this;
  397.  
  398.                 this.box.addEventListener(
  399.                     "select",
  400.                     function(e){
  401.                         self.onSelect(e);
  402.                     },
  403.                     true
  404.                 );
  405.             },
  406.             _currItem: null,
  407.             onSelect: function(e){
  408.                 var i = this.box.getSelectedItem(0);
  409.                 if(this._currItem){
  410.                     this._currItem.setAttribute("image", 
  411.                         "chrome://foxmarks/skin/images/restore_icon.png");
  412.                 }
  413.                 this._currItem = i;
  414.                 this._currItem.setAttribute("image", 
  415.                     "chrome://foxmarks/skin/images/restore_icon_selected.png");
  416.             },
  417.             onSyncComplete: function(){
  418.                 if(this.box && this._data){
  419.                     var item = this.box.getItemAtIndex(0);
  420.                     if(item){
  421.                         var currVersion = Xmarks.gSettings.GetSyncRevision("bookmarks");
  422.                         if(item.value != currVersion){
  423.                             var formatString = Xmarks.Bundle().GetStringFromName(
  424.                                 "restore.formatstring"
  425.                             );
  426.                             var d = new Date(Xmarks.gSettings.lastSynchDate);
  427.                             var s = d.toLocaleFormat(formatString);
  428.                             var i = this.box.insertItemAt(0, s, currVersion);
  429.                             i.className = "listitem-iconic";
  430.                             i.style.paddingLeft = "6px";
  431.                             i.setAttribute("image",  "chrome://foxmarks/skin/images/restore_icon.png");
  432.                             this.box.selectItem(
  433.                                 this.box.getItemAtIndex(0)
  434.                             );
  435.                         }
  436.                     }
  437.                 }
  438.             },
  439.             onShow: function(){
  440.                 if(!Xmarks.gSettings.getHaveSynced("bookmarks") ||
  441.                     Xmarks.gSettings.viewId != 0 || 
  442.                     Xmarks.gSettings.useOwnServer){
  443.                     document.getElementById("foxmarks-restoredesc").hidden=true;
  444.                     document.getElementById("foxmarks-restorebox").hidden=true;
  445.                     if(Xmarks.gSettings.viewId){
  446.                         document.getElementById("foxmarks-restoreprofile").
  447.                             hidden=false;
  448.                     } else if(Xmarks.gSettings.useOwnServer){
  449.                         document.getElementById("foxmarks-restoreownuser").
  450.                             hidden=false;
  451.                     } else {
  452.                         document.getElementById("foxmarks-restorenewuser").
  453.                             hidden=false;
  454.                     }
  455.                 } else {
  456.                     document.getElementById("foxmarks-restoredesc").hidden=
  457.                         false;
  458.                     document.getElementById("foxmarks-restorebox").hidden=
  459.                         false;
  460.                     document.getElementById("foxmarks-restorenewuser").hidden=true;
  461.                     document.getElementById("foxmarks-restoreownuser").hidden=true;
  462.                     if(!this._data){
  463.                         var self = this;
  464.                         Xmarks.FetchRevisions(
  465.                             function(data){
  466.                                 self.loadRevisions(data);
  467.                             }
  468.                         );
  469.                     } else {
  470.                         this.box.focus();
  471.                     }
  472.                 }
  473.             },
  474.             loadRevisions: function(response){
  475.                 this.box.removeItemAt(0);
  476.                 if (response.status != 0) {
  477.                     this.box.appendItem(
  478.                             Xmarks.Bundle().GetStringFromName(
  479.                                 "err.revisionserror"));
  480.                     this._data = true;
  481.                     return;
  482.                 }
  483.                 else if (!response.revisions || response.revisions.length == 0){
  484.                     this.box.appendItem(
  485.                             Xmarks.Bundle().GetStringFromName(
  486.                                 "err.norevisionsloaded"));
  487.                     this._data = true;;
  488.                     return;
  489.  
  490.                 }
  491.  
  492.                 var list = response.revisions;
  493.                 list.sort(
  494.                     function(a,b){
  495.                         return b.revision - a.revision;
  496.                     }
  497.                 );
  498.  
  499.                 this._data = list;
  500.                 var len = list.length;
  501.                 var formatString = Xmarks.Bundle().GetStringFromName(
  502.                     "restore.formatstring"
  503.                 );
  504.                 for(x = 0; x < len; x++){
  505.                     var item = list[x];
  506.                     var d = new Date(item.created * 1000 );
  507.                     var s = d.toLocaleFormat(formatString);
  508.                     var i = this.box.appendItem(s, item.revision);
  509.                     i.className = "listitem-iconic";
  510.                     i.style.paddingLeft = "6px";
  511.                     i.setAttribute("image",  "chrome://foxmarks/skin/images/restore_icon.png");
  512.                 }
  513.                 this.box.disabled = false;
  514.                 this.box.selectItem(
  515.                     this.box.getItemAtIndex(0)
  516.                 );
  517.                 this.box.focus();
  518.                 document.getElementById("foxmarks-viewrestore").disabled
  519.                     = false;
  520.                 document.getElementById("foxmarks-dorestore").disabled = false;
  521.             },
  522.             onOK: function(){
  523.  
  524.             },
  525.             onCancel: function(){
  526.  
  527.             },
  528.             select: function(){
  529.                     return false;
  530.             },
  531.             restore: function(){
  532.                 var item = this.box.getSelectedItem(0);
  533.                 var val = item.value;
  534.                 this.box.focus();
  535.                 if(this.box.getIndexOfItem(item) == 0){
  536.                     this.mgr.downloadNow(false, true);
  537.                 } else {
  538.                     this.mgr.restore(val);
  539.                 }
  540.             },
  541.             viewRestore: function(){
  542.                 var item = this.box.getSelectedItem(0);
  543.                 var val = item.value;
  544.                 this.box.focus();
  545.  
  546.                 Xmarks.OpenInNewTabAuth(
  547.                     Xmarks.gSettings.httpProtocol +  Xmarks.gSettings.myHost +
  548.                     "/bookmarks/view/" + val + "/", 
  549.                     true,
  550.                     Xmarks.gSettings.auth
  551.                 );
  552.             }
  553.         },
  554.         profile: { // profiles tab
  555.            onSetup: function(mgr){
  556.                 this.mgr = mgr;
  557.                 this.settingChanged();
  558.            },
  559.            onOK: function(){
  560.  
  561.            },
  562.  
  563.            onCancel: function(){
  564.  
  565.            },
  566.            myFoxmarks: function(){
  567.                 if(Xmarks.gSettings.securityLevel == 1){
  568.                     Xmarks.OpenInNewTab("https://my.xmarks.com/?mode=profiles", true);
  569.                 } else { 
  570.                     Xmarks.OpenInNewTab("http://my.xmarks.com/?mode=profiles", true);
  571.                 }
  572.            },
  573.            changeProfile: function() {
  574.                 var retval = {};
  575.                 window.openDialog(
  576.                     "chrome://foxmarks/content/foxmarks-changeprofile.xul",
  577.                     "Xmarks", "modal,centerscreen", retval
  578.                 );
  579.  
  580.                 if (retval.newProfileId &&
  581.                     retval.newProfileId != Xmarks.gSettings.viewId) {
  582.                     var ps = Components.
  583.                         classes["@mozilla.org/embedcomp/prompt-service;1"]
  584.                         .getService(Components.interfaces.nsIPromptService);
  585.                     if (ps.confirm(null, "Xmarks",
  586.                         Xmarks.Bundle().GetStringFromName("msg.profilechanged"))) {
  587.                         if (this.mgr.synchronizeNow()) {
  588.                             var prefwindow = 
  589.                                 document.getElementById("foxmarks-settings");
  590.                             prefwindow.showPane(
  591.                                 document.getElementById("foxmarks-mainpane")
  592.                             );
  593.                             return;
  594.                         }
  595.                         Xmarks.gSettings.viewId = retval.newProfileId;
  596.                         Xmarks.gSettings.viewName = retval.newProfileName;
  597.                         this.mgr.downloadNow(true);
  598.                         this.settingChanged();
  599.                     }
  600.                 }
  601.             },
  602.             settingChanged: function() {
  603.                 document.getElementById("profileName").value =
  604.                     Xmarks.gSettings.viewName;
  605.             }
  606.         },
  607.         // Advanced tab
  608.         discover: { 
  609.            onSearchBoostChanged: function(){
  610.                 this.onOK();
  611.            },
  612.            onSetup: function(mgr){
  613.                 document.getElementById("tagsuggest").checked =
  614.                     Xmarks.gSettings.tagSuggestionsEnabled;
  615.                 document.getElementById("siteboost").checked =
  616.                     Xmarks.gSettings.simsiteEnabled;
  617.                 document.getElementById("searchboost").checked = 
  618.                     Xmarks.gSettings.serpEnabled;
  619.                 this.data = {
  620.                     tagSuggestionsEnabled: 
  621.                         Xmarks.gSettings.tagSuggestionsEnabled,
  622.                     serpEnabled: Xmarks.gSettings.serpEnabled,
  623.                     simsiteEnabled: Xmarks.gSettings.simsiteEnabled
  624.                 };
  625.            },
  626.            onOK: function(){
  627.                 Xmarks.gSettings.tagSuggestionsEnabled = 
  628.                     document.getElementById("tagsuggest").checked;
  629.                 Xmarks.gSettings.serpEnabled = 
  630.                     document.getElementById("searchboost").checked;
  631.                 Xmarks.gSettings.simsiteEnabled = 
  632.                     document.getElementById("siteboost").checked;
  633.                 Xmarks.gSettings.tagSuggestionsEnabled = 
  634.                     document.getElementById("tagsuggest").checked;
  635.            },
  636.            onCancel: function(){
  637.                 var name;
  638.                 for(name in this.data){
  639.                     if(this.data.hasOwnProperty(name)){
  640.                         Xmarks.gSettings[name] = this.data[name];
  641.                     }
  642.                 }
  643.            }
  644.         },
  645.         // Advanced tab
  646.         advanced: { 
  647.            onSetup: function(mgr){
  648.                 this.data = {
  649.                     enableLogging: Xmarks.gSettings.enableLogging,
  650.                     securityLevel: Xmarks.gSettings.securityLevel,
  651.                     url: Xmarks.gSettings.url,
  652.                     passwordurl: Xmarks.gSettings.passwordurl
  653.                 };
  654.                 this.useOwnServerChanged();
  655.            },
  656.            verifyOK: function(){
  657.                 var uo = document.getElementById("useown").checked;
  658.  
  659.                 if(uo){
  660.                     var s = document.getElementById("url").value;
  661.                     if(s.length == 0){
  662.                         Xmarks.Alert(Xmarks.Bundle().
  663.                             GetStringFromName("error.nourlownserver"));
  664.                         return false;
  665.                     }
  666.                     var exp = /(.*):\/\/([^\/]*)/;
  667.                     var result = s.match(exp);
  668.                     if (!result || result.length < 2) {
  669.                         Xmarks.Alert(Xmarks.Bundle().
  670.                             GetStringFromName("error.nourlownserver"));
  671.                         return false;
  672.                     }
  673.                     Xmarks.gSettings.useOwnServer = uo;
  674.                 }
  675.  
  676.                 return true;
  677.            },
  678.            onOK: function(){
  679.                 var uo = document.getElementById("useown").checked;
  680.                 Xmarks.gSettings.useOwnServer = uo;
  681.                 if(uo){
  682.                     Xmarks.gSettings.url = document.getElementById("url").value;
  683.                     Xmarks.gSettings.passwordurl =
  684.                         document.getElementById("passwordurl").value;
  685.                 }
  686.            },
  687.            onCancel: function(){
  688.                 var name;
  689.                 for(name in this.data){
  690.                     if(this.data.hasOwnProperty(name)){
  691.                         Xmarks.gSettings[name] = this.data[name];
  692.                     }
  693.                 }
  694.            },
  695.            displayLogFile: function() {
  696.                 var ios = Cc["@mozilla.org/network/io-service;1"].
  697.                     getService(Ci.nsIIOService);
  698.                 var file = Cc['@mozilla.org/file/directory_service;1']
  699.                     .getService(Ci.nsIProperties) .get('ProfD', Ci.nsIFile);
  700.  
  701.                 file.append("xmarks.log");
  702.                 var uri = ios.newFileURI(file);
  703.                 Xmarks.OpenInNewWindow(uri.spec);
  704.            },
  705.           useOwnServerChanged: function() {
  706.                 var uo = document.getElementById("useown").checked;
  707.                 document.getElementById("url").disabled = !uo;
  708.                 document.getElementById("useown-url-label").disabled = !uo;
  709.                 document.getElementById("passwordurl").disabled = !uo;
  710.                 document.getElementById("useown-passwordurl-label").disabled =
  711.                     !uo;
  712.                 document.getElementById("encrypt").disabled = uo;
  713.                 document.getElementById("profileChangeButton").disabled = uo;
  714.                 if (!Xmarks.gSettings.haveSynced && !Xmarks.gSettings.username) {
  715.                     document.getElementById("foxmarks-statusdeck")
  716.                         .selectedIndex = uo ? 0 :1;
  717.                 }
  718.             },
  719.            useOwnServer: function(){
  720.                 var uo = document.getElementById("useown").checked;
  721.                 if(!uo){
  722.                     return true;
  723.                 }
  724.                     
  725.                 var params = {
  726.                     url: document.getElementById("url").value,
  727.                     purl: document.getElementById("passwordurl").value,
  728.                     psync: document.getElementById("sync-passwords").checked,
  729.                     result: false
  730.                 };
  731.                 window.openDialog(
  732.                     "chrome://foxmarks/content/foxmarks-ownserverdlg.xul",
  733.                     "_blank",
  734.                     "chrome,dialog,modal,centerscreen", params);
  735.                 if(params.result){
  736.                     document.getElementById("url").value = params.url;
  737.                     document.getElementById("passwordurl").value = params.purl;
  738.                 } else {
  739.                     document.getElementById("useown").checked = false;
  740.                 }
  741.                 this.useOwnServerChanged();
  742.                 return true;
  743.            },
  744.            moreOwnServer: function(){
  745.                 Xmarks.OpenInNewWindow("http://wiki.xmarks.com/wiki/Foxmarks:_Frequently_Asked_Questions#Using_Other_Servers"); 
  746.            }
  747.         }
  748.     },
  749.  
  750.     _forEachPane: function(method, args){
  751.         var name;
  752.         for(name in this.panes){
  753.             if(this.panes.hasOwnProperty(name)){
  754.                 var pane = this.panes[name];
  755.                 if(typeof(method) == "string"){
  756.                     pane[method].apply(pane, args);
  757.                 }
  758.                 else {
  759.                     if(args === undefined){
  760.                         args = [];
  761.  
  762.                     }
  763.                     args.splice(0,0,this.panes[name]);
  764.                     method.apply(pane, args);
  765.                 }
  766.             }
  767.         }
  768.     },
  769.  
  770.     onSetup: function(){
  771.         this._forEachPane("onSetup", [this]);
  772.  
  773.         // Set styles for Mac OS X
  774.         if (navigator.platform.toLowerCase().indexOf('mac') > -1 ||
  775.             navigator.platform.toLowerCase().indexOf('linux') > -1) {
  776.             document.getElementById("foxmarks-settings").className = "macosx";
  777.         }
  778.         // Set server ping
  779.         if (!Xmarks.gSettings.useOwnServer) {
  780.             var attrs = [];
  781.             attrs.push("app="       + "jezebel");
  782.             attrs.push("mid="       + Xmarks.gSettings.machineId);
  783.             attrs.push("page="      + "settings");
  784.             attrs.push("username="  + Xmarks.gSettings.username);
  785.             attrs.push("no_cache="  + Date.now().toString(36));
  786.             var query = attrs.join("&");
  787.  
  788.             document.getElementById("ping").src = 
  789.                 "http://tr.xmarks.com/tracking/impressions.gif?" + query; 
  790.         }
  791.  
  792.         // Info that is read-only
  793.         this._lastSyncDateChanged();
  794.         document.getElementById("version").value = 
  795.             "v"
  796.             + Xmarks.FoxmarksVersion();
  797.         try {
  798.             window.sizeToContent();
  799.         } catch(e) {}
  800.  
  801.         var prefwindow = document.getElementById("foxmarks-settings");
  802.         var self = this;
  803.         prefwindow.onclick = function(e) { self.onClick(e);};
  804.         prefwindow.showPane(
  805.             document.getElementById(window.arguments[0] || "foxmarks-mainpane")
  806.         );
  807.  
  808.     },
  809.     onOK: function(){
  810.         if(!this.panes.advanced.verifyOK()){
  811.            return false;
  812.         }
  813.         this._forEachPane("onOK");
  814.         Xmarks.gSettings.password = 
  815.             document.getElementById("password").value;
  816.         var os = Cc["@mozilla.org/observer-service;1"]
  817.             .getService(Ci.nsIObserverService);
  818.         os.notifyObservers(null, "foxmarks-settingschange","");
  819.         return true;
  820.     },
  821.     onCancel: function(){
  822.         if (navigator.platform.toLowerCase().indexOf('mac') > -1 ||
  823.             navigator.platform.toLowerCase().indexOf('linux') > -1) {
  824.             if(!this.panes.advanced.verifyOK()){
  825.                 return false;
  826.             }
  827.             this._forEachPane("onOK");
  828.             var os = Cc["@mozilla.org/observer-service;1"]
  829.                 .getService(Ci.nsIObserverService);
  830.             os.notifyObservers(null, "foxmarks-settingschange","");
  831.         }
  832.         else {
  833.             this._forEachPane("onCancel");
  834.         }
  835.         return true;
  836.     },
  837.     onHelp: function(){
  838.         Xmarks.OpenInNewWindow("http://wiki.xmarks.com/wiki/Foxmarks:_Help");
  839.     },
  840.     runSetupWizard: function(){
  841.         this.onOK();
  842.         if(Xmarks.gSettings.useOwnServer){
  843.             Xmarks.Alert(Xmarks.Bundle().
  844.                 GetStringFromName("error.nowizforownserver"));
  845.         } else {
  846.             Xmarks.OpenWizard(true);
  847.             window.close();
  848.         }
  849.     },
  850.     onSyncComplete: function(){
  851.         this._lastSyncDateChanged();
  852.         this.panes.restore.onSyncComplete();
  853.     },
  854.     synchronizeNow: function() {
  855.         var retval = 0;
  856.         this.onOK();
  857.         var retval = Xmarks.PerformAction("synch", null);
  858.         this.onSyncComplete();
  859.         this.panes.general.resetNameAndPassword();
  860.         this.panes.sync.resetSyncTypes();
  861.         return retval;
  862.     },
  863.     _lastSyncDateChanged: function() {
  864.         document.getElementById("lastSynchDate").value = 
  865.             Xmarks.gSettings.lastSynchDisplayDate;
  866.     },
  867.     uploadNow: function(){
  868.         var retval = 0;
  869.         var ps = Components.classes
  870.             ["@mozilla.org/embedcomp/prompt-service;1"]
  871.             .getService(Components.interfaces.nsIPromptService);
  872.         if (ps.confirm(null, "Xmarks",
  873.             Xmarks.Bundle().GetStringFromName("msg.overwriteremote"))) {
  874.             this.onOK();
  875.             retval = Xmarks.PerformAction("upload", null);
  876.             if(retval){
  877.                var prefwindow = document.getElementById("foxmarks-settings");
  878.                prefwindow.showPane(
  879.                     document.getElementById("foxmarks-mainpane")
  880.                );
  881.             }
  882.             this.onSyncComplete();
  883.         }
  884.         return retval;
  885.     },
  886.     restore: function(rev){
  887.         var retval = 0;
  888.         var ps = Components.classes
  889.             ["@mozilla.org/embedcomp/prompt-service;1"]
  890.             .getService(Components.interfaces.nsIPromptService);
  891.         if (ps.confirm(null, "Xmarks",
  892.                 Xmarks.Bundle().GetStringFromName("restore.confirm"))) {
  893.             this.onOK();
  894.             retval = Xmarks.PerformAction("restore", rev);
  895.             if(retval){
  896.                var prefwindow = document.getElementById("foxmarks-settings");
  897.                prefwindow.showPane(
  898.                     document.getElementById("foxmarks-mainpane")
  899.                );
  900.             }
  901.             ps.alert(null, "Xmarks", Xmarks.Bundle().
  902.                     GetStringFromName("restore.success"));
  903.             this.onSyncComplete();
  904.         }
  905.         return retval;
  906.  
  907.     },
  908.     downloadNow: function(silent, isrestore){
  909.         var retval = 0;
  910.         var ps = Components.classes
  911.             ["@mozilla.org/embedcomp/prompt-service;1"]
  912.             .getService(Components.interfaces.nsIPromptService);
  913.         if (silent
  914.             || ps.confirm(null, "Xmarks",
  915.                 Xmarks.Bundle().GetStringFromName(
  916.                     isrestore ? "restore.confirm" :"msg.overwritelocal"))) {
  917.             this.onOK();
  918.             retval = Xmarks.PerformAction("download", null);
  919.             if(retval){
  920.                var prefwindow = document.getElementById("foxmarks-settings");
  921.                prefwindow.showPane(
  922.                     document.getElementById("foxmarks-mainpane")
  923.                );
  924.             }
  925.             this.onSyncComplete();
  926.         }
  927.         return retval;
  928.  
  929.     },
  930.     onClick: function(e){
  931.         if(e && e.target && e.target.id == "foxmarks-settings"){
  932.             var self = this;
  933.             var prefwindow = document.getElementById("foxmarks-settings");
  934.             window.setTimeout(
  935.                 function(){
  936.                     if(prefwindow.currentPane.id == "foxmarks-restorepane"){
  937.                         self.panes.restore.onShow();
  938.                     }
  939.                 },
  940.                 0
  941.             );
  942.         }
  943.     },
  944.     onUnload: function(){
  945.         this.panes.status.onUnload();
  946.     }
  947. };
  948.  
  949.  
  950.  
  951. function SynchronizeForever() {
  952.     while (!SynchronizeNow()) { };
  953. }
  954.  
  955.  
  956.